<%@ page language="java" pageEncoding="utf-8" %>

<!DOCTYPE html>
<html>
<head>
    <%@include file="../common/base.jsp"%>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1"/>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache,must-revalidate">
    <meta http-equiv="expires" content="0">
    <title>等待应答</title>
    <link rel="stylesheet" type="text/css" href="${base}/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="${base}/css/global.css?version=${version}">
    <link rel="stylesheet" type="text/css" href="${base}/css/takecar.css?version=${version}">
    <style>
        body{
            position: absolute;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            min-height: 510px;
        }
        .l-footer{
            position: absolute;

        }
    </style>
</head>
<body>
<div class="container-fluid">
    <div class="waiting-reply">
        <img class="img" src="${base}/images/reply.gif">
        <div class="text">
            <p id="timing">00:00</p>
            <p>订单推送中</p>
            <p>请稍后...</p>
        </div>
    </div>
    <div class="divBox router-info">
        <p>
            <img class="img img1" src="${base}/images/time.png">
            <span id="creadtime">13:20</span>
        </p>
        <p>
            <img class="img img2" src="${base}/images/qidian.png">
            <span id="originDetailAddressText">起始地</span>
        </p>
        <p>
            <img class="img img3" src="${base}/images/zhongdian.png">
            <span id="destDetailAddressText">终点</span>
        </p>
    </div>
    <div class="l-footer">
        <a class="cancelBox">
            <img src="${base}/images/cancel.png">
            <p class="text">取消订单</p>
        </a>
        <%@include file="footer.jsp"%>
    </div>

</div>
</body>

<script type="text/javascript" src="${base}/js/jquery.min.js"></script>
<script type="text/javascript" src="${base}/plugin/layer-v3.0.3/layer.js"></script>
<%--<script type="text/javascript" src="${base}/plugin/crypto-js/crypto-js.min.js"></script>--%>
<%--<script type="text/javascript" src="${base}/plugin/jsencrypt/jsencrypt.min.js"></script>--%>
<script type="text/javascript" src="${base}/js/localStorageOpt.js"></script>

<script type="text/javascript" src="${base}/js/constant.js?version=${version}"></script>
<script type="text/javascript" src="${base}/js/utils.js?version=${version}"></script>
<script type="text/javascript">

    jQuery(document).ready(function ($) {
        var yun=new yueajax( "${openId}");
        var times;
        var $document = $(document);
        $document.on('touchend', '.cancelBox', function (event) {
            layer.confirm('正在为您寻找车辆，再耐心等待一会儿吧', {
                title: "取消叫车",
                btn: ['不等了', '再等一会'] //按钮
            }, function (index) {
                //调用后台取消接口
                yun.ajax_md5({orderUuid:yun.orderUuid},"${base}/api/v1/passenger/token/order/cancel",function(){
//                    window.location.href = "/yue/index";
                    changeUrl('index');
                },function(){
                    alert("订单取消失败");
                    changeUrl('index')

//                    window.location.href = "/yue/index";
                });
                layer.close(index);
            }, function (index) {
                layer.close(index);
            });
        });
        //初始化请求订单数据
        getOrderStatus(function (data) {
            times=(data.data.countdown);
            countDown();
//            订单创建时间
            var cTime=new Date(data.data.deparTime || data.data.createOn);
            console.log(cTime);
            var cTobj=yun.time_count(cTime)
            $('#creadtime').html(cTobj.day+'  '+cTobj.hour+cTime.format('hh:mm'));
            $("#originDetailAddressText").html(data.data.originAddress);
            $("#destDetailAddressText").html(data.data.destAddress);
        });
        //定时请求OrderDetail，获取订单详情，当有司机接单的时候，自动跳转到、yue/wmeeting
        var interval= setInterval(getOrderStatus, 5000);
        //获取订单信息
        function getOrderStatus(callback) {
            yun.order_ajax(function(data){
                if (data.data.subStatus == 100 || data.data.subStatus == 900){}else {changeUrl(data.data.subStatus,yun.orderUuid);}
                if(typeof callback =="function"){
                    callback(data);
                }
                if(data.data.subStatus == 900){
                    isNewOrder();
                }
            },function (data) {
                layer.msg(data.msg);
            });

        }

//        五分钟计时，等待接单,times 是时间戳
        function countDown(){
            var s=parseInt(times%(1000*60)/1000);
            var m=parseInt(times/(1000*60));
            if(m<10){m="0"+m.toString()};
            if(s<10){s="0"+s.toString()};
            $('#timing').html(m+':'+s);
            if(m==5){
                isNewOrder();
                return ;
            }
            times+=1000;
            setTimeout(countDown,1000);
        }
//        重新叫单
        function isNewOrder(){
            clearInterval(interval);
            layer.confirm('暂时没有司机应答，您要取消本次叫车吗？', {
                title: "取消叫车",
                closeBtn:0,
                btn: ['重新叫车', '取消叫车'] //按钮
            }, function (index) {
                yun.ajax_md5(
                    {orderUuid:yun.orderUuid},
                    "${base}/api/v1/passenger/token/order/callAgain",
                    function(data){
                        layer.close(index);
                        url.setUrlPara({orderUuid:data.data.uuid})
//                                window.location.href=window.location.pathname+'&orderUuid='+data.data.uuid;
//                                window.location.reload();
//                                interval= setInterval(getOrderStatus, 5000);
                    },
                    function(){
                        layer.msg(data.msg,function(){
                            changeUrl('index');
                        })
                    }
                );
                layer.close(index);
            }, function (index) {
                //调用后台取消接口
                yun.ajax_md5({orderUuid:yun.orderUuid},"${base}/api/v1/passenger/token/order/cancel",function(){
//                    window.location.href = "/yue/index";
                    changeUrl('index')
                },function(){
                    alert("订单取消失败");
//                    window.location.href = "/yue/index";
                    changeUrl('index');
                });
                layer.close(index);
            });
        }


        // 五分钟计时，等待接单
//        var ele_timer = document.getElementById("timing");
//        var n_sec = 0; //秒
//        var n_min = 0; //分
//        function timer() {
//            return setInterval(function () {
//                var str_sec = n_sec;
//                var str_min = n_min;
//                if (n_sec < 10) {
//                    str_sec = "0" + n_sec;
//                }
//                if (n_min < 10) {
//                    str_min = "0" + n_min;
//                }
//                var time = str_min + ":" + str_sec;
//                ele_timer.innerHTML = time;
//                n_sec++;
//                if (n_sec > 59) {
//                    n_sec = 0;
//                    n_min++;
//                }
//                if (n_min > 4) {
//                    n_sec = 0;
//                }
//            }, 1000);
//        }
//        var n_timer = timer();


    });
</script>
</html>